<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="parent">
        <div class="test"></div>
    </div>
    <!-- <style>
        /* 1 */
        .parent {
            border: 2px solid #333;
            width: 100px;
            height: 100px;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }

        .test {
            width: 40px;
            height: 40px;
            background-color: pink;
        }
    </style> -->
    <!-- 2 -->
    <!-- <style>
        .parent {
            position: relative;
            border: 2px solid #333;
            width: 100px;
            height: 100px;
        }

        .test {
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
            width: 40px;
            height: 40px;
            background-color: pink;
        }
    </style> -->
    <!-- 3 -->
    <!-- 1.top:50%;
    2.left50%;
    3.transform:translate(-50%,-50%);向左向上走自身宽高的50% -->
    <!-- <style>
        .parent {
            position: relative;
            border: 2px solid #333;
            width: 100px;
            height: 100px;
        }

        .test {
            position: absolute;
            width: 40px;
            height: 40px;
            background-color: pink;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            margin: auto;
        }
    </style> -->
</body>

</html>